﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>自定义focusColor插件</title>
        <script type="text/javascript" src="http://www.imooc.com/data/jquery-1.8.2.min.js"></script>
        <style>
            .fl{ 
                background:purple; 
                padding:5px; 
                color:white;
            }
            .content ul li span{ 
                padding-right:20px;
            }
            .content ul li{
               background:aquamarine; 
            }
        </style>
    </head>
    
    <body>
        <div id="divtest">
            <div class="title">
                <span class="fl">自定义focusColor插件</span>
            </div>
            <div class="content">
                <ul id="test">
                    <li><span>橘子</span><span>水果</span></li>
                    <li><span>芹菜</span><span>蔬菜</span></li>
                    <li><span>香蕉</span><span>水果</span></li>
                </ul>
            </div>
        </div>
        
        
        <script type = "text/javascript">
            $(function(){
                $("#test li").each(function(index){
                    $(this).focusColor("gray");
                });
            });
            (function ($) {
                $.fn.extend({
                    "focusColor": function (newColor) {
                       var oldColor = $(this).css('background-color');
                       $(this).hover(
                           function(){
                               $(this).css('background-color',newColor)
                               
                           },
                           function(){
                               $(this).css('background-color',oldColor)
                               
                           }
                       );
                       return $(this);
                    }
                });
            })(jQuery);
            
            
            
        </script>
    </body>
</html>